package com.gree.commom.result;

import com.github.pagehelper.PageInfo;
import com.gree.commom.enums.BaseResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * 公共保存状态返回对象
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class BaseResult {
    // 状态编码
    private Integer code;
    // 状态描述
    private String message;
    // 相应数据
    private Object data;

    // 分页对象(商品列表需要-pom.xml添加依赖)
    PageInfo<?> pageInfo;

    //成功返回的对象
    public static BaseResult success() {
        BaseResult result = new BaseResult();
        result.setCode(BaseResultEnum.SUCCESS.getCode());
        result.setMessage(BaseResultEnum.SUCCESS.getMessage());
        return result;
    }

    //成功返回的对象-带分页对象
    public static BaseResult success(PageInfo<?> pageInfo) {
        BaseResult result = new BaseResult();
        result.setCode(BaseResultEnum.SUCCESS.getCode());
        result.setMessage(BaseResultEnum.SUCCESS.getMessage());
        result.setPageInfo(pageInfo);
        return result;
    }

    //失败返回的对象
    public static BaseResult error() {
        BaseResult result = new BaseResult();
        result.setCode(BaseResultEnum.ERROR.getCode());
        result.setMessage(BaseResultEnum.ERROR.getMessage());
        return result;
    }
}
